package starlingui.manager
{
	import com.imcrl.manager.Pool;
	
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	
	import starling.textures.Texture;

	public class TextureResource
	{
		private var dic:Dictionary;
		public function TextureResource()
		{
			dic=new Dictionary(true);
		}
		
		private static var sharedEmptyTextures:Dictionary=new Dictionary();
		public static function getEmpty(width:int=64, height:int=64,saveIt:Boolean=true):Texture{
			var texture:Texture;
			var key:String=width+","+height;
			texture=sharedEmptyTextures[key];
			if(texture==null){
				texture=Texture.empty(width,height);
			}
			if(saveIt){
				sharedEmptyTextures[key]=texture;
			}
			return texture;
		}
		
		private static var ins:TextureResource=new TextureResource;
		public static function getURL(url:String):TextureLoader{
			return ins.getURL(url);
		}
		
		public static function getTextureByKey(value:String):Texture{
			return ins.dic[value];
		}
		
		public static function setTextureByKey(key:String,value:Texture):void{
			ins.dic[key]=value;
		}
		
		private function getLoader():TextureLoader{
			return new TextureLoader();
		}
		
		public function getURL(url:String):TextureLoader{
			var loader:TextureLoader=dic[url];
			if(loader==null){
				loader=getLoader();
				loader.load(url);
				
				dic[url]=loader;
			}
			return loader;
		}

		
		
	}
}